// test_vector_store_service.js - 测试向量存储服务
require('dotenv').config();
const vectorStoreService = require('./services/vectorStoreService');

async function testVectorStoreService() {
    try {
        console.log("开始测试向量存储服务...");
        
        // 1. 测试搜索功能（应该会自动创建向量存储）
        console.log("\n1. 测试搜索功能...");
        const searchResults = await vectorStoreService.searchKnowledgePoints("React Hooks", 2);
        console.log("搜索结果:", searchResults.length, "条");
        if (searchResults.length > 0) {
            searchResults.forEach((result, index) => {
                console.log(`结果 ${index + 1}: ${result.content ? result.content.substring(0, 100) : '无内容'}...`);
            });
        }
        
        // 2. 测试添加知识点功能
        console.log("\n2. 测试添加知识点功能...");
        const testKnowledgePoint = {
            _id: "test_" + Date.now(),
            content: "React Hooks是React 16.8版本引入的新特性，它允许你在不编写class的情况下使用state以及其他的React特性。"
        };
        
        await vectorStoreService.addKnowledgePointToStore(testKnowledgePoint);
        
        // 3. 再次测试搜索功能
        console.log("\n3. 再次测试搜索功能...");
        const searchResults2 = await vectorStoreService.searchKnowledgePoints("React Hooks", 2);
        console.log("搜索结果:", searchResults2.length, "条");
        if (searchResults2.length > 0) {
            searchResults2.forEach((result, index) => {
                console.log(`结果 ${index + 1}: ${result.content ? result.content.substring(0, 100) : '无内容'}...`);
            });
        }
        
        console.log("\n向量存储服务测试完成！");
    } catch (error) {
        console.error("测试向量存储服务失败:", error);
    }
}

// 运行测试
testVectorStoreService();